From: Giovanni Campagna Date: Sun, 12 May 2013 18:13:08 +0000 (+0200) Subject: Hash: make .size() constant time X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~4194 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=b0dc841e00d2f99af4bdfbe60800c74f0c89f50c;p=gnome-shell.git Hash: make .size() constant time MessageTray calls .size() very often to update the no messages label, so a linear time implementation is not good enough. https://bugzilla.gnome.org/show_bug.cgi?id=700194 --- diff --git a/js/misc/hash.js b/js/misc/hash.js index 19d4df619..db70d6542 100644 --- a/js/misc/hash.js +++ b/js/misc/hash.js @@ -58,6 +58,7 @@ const Map = new Lang.Class({ _init: function(iterable) { this._pool = { }; + this._size = 0; if (iterable) { for (let i = 0; i < iterable.length; i++) { @@ -99,6 +100,7 @@ const Map = new Lang.Class({ node.value = value; } else { this._pool[hash] = { key: key, value: value }; + this._size++; } }, @@ -108,6 +110,7 @@ const Map = new Lang.Class({ if (node && _sameValue(node.key, key)) { delete this._pool[hash]; + this._size--; return [node.key, node.value]; } else { return [null, null]; @@ -136,6 +139,6 @@ const Map = new Lang.Class({ }, size: function() { - return Object.getOwnPropertyNames(this._pool).length; + return this._size; }, });